package com.itheima.user.web;

import com.itheima.user.config.PatternProperties;
import com.itheima.user.pojo.User;
import com.itheima.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.text.DateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author 29143
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserWeb {

    @Autowired
    private UserService userService;

    @Autowired
    PatternProperties patternProperties;


    @GetMapping("/{id}")
    public User findUserById(@PathVariable("id") Long id,@RequestHeader(value = "name",required = false) String name){
        System.out.println(name);
        return userService.findUserById(id);
    }


    @GetMapping("/now")
    public String now(){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(patternProperties.getDateformat()));
    }

    @PostMapping
    public User save(@RequestBody User user){
        System.out.println("保存用户");
        return null;
    }

    @GetMapping("prop")
    public PatternProperties prop(){
        return patternProperties;
    }

}
